package com.nq.activaity.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nq.activaity.dto.UserSpecifiedPrizeResp;
import com.nq.activaity.entity.StUserSpecifiedPrize;
import com.nq.activaity.service.IStUserSpecifiedPrizeService;
import com.nq.common.Result;
import com.nq.common.system.query.QueryGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;

/**
 * @Description: 用户指定奖品表
 * @Author: jeecg-boot
 * @Date:   2024-11-06
 * @Version: V1.0
 */
@RestController
@RequestMapping("/st/stUserSpecifiedPrize")
@Slf4j
public class StUserSpecifiedPrizeController  {
	@Autowired
	private IStUserSpecifiedPrizeService stUserSpecifiedPrizeService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stUserSpecifiedPrize
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@GetMapping(value = "/list")
	public Result<?> queryPageList(StUserSpecifiedPrize stUserSpecifiedPrize,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {

		QueryWrapper<StUserSpecifiedPrize> queryWrapper = QueryGenerator.initQueryWrapper(stUserSpecifiedPrize, req.getParameterMap());
		Page<StUserSpecifiedPrize> page = new Page<StUserSpecifiedPrize>(pageNo, pageSize);
		IPage<UserSpecifiedPrizeResp> pageList = stUserSpecifiedPrizeService.queryPageList(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stUserSpecifiedPrize
	 * @return
	 */
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody StUserSpecifiedPrize stUserSpecifiedPrize) {
		stUserSpecifiedPrize.setCreateTime(new Date());
		return stUserSpecifiedPrizeService.addSpecifiedPrize(stUserSpecifiedPrize);
	}
	
	/**
	 *  编辑
	 *
	 * @param stUserSpecifiedPrize
	 * @return
	 */
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody StUserSpecifiedPrize stUserSpecifiedPrize) {
		stUserSpecifiedPrizeService.editSpecifiedPrize(stUserSpecifiedPrize);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		stUserSpecifiedPrizeService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stUserSpecifiedPrizeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		StUserSpecifiedPrize stUserSpecifiedPrize = stUserSpecifiedPrizeService.getById(id);
		if(stUserSpecifiedPrize==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stUserSpecifiedPrize);
	}
//
//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param stUserSpecifiedPrize
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, StUserSpecifiedPrize stUserSpecifiedPrize) {
//        return super.exportXls(request, stUserSpecifiedPrize, StUserSpecifiedPrize.class, "用户指定奖品表");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, StUserSpecifiedPrize.class);
//    }

}
